package com.bsoft.gol.hcs.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author tongtp
 * @version v0.1
 * @Package utils
 * @className ResponseUtils
 * @description
 * @create 2020-10-09 9:09
 **/
public class ResponseUtils {

	public ResponseUtils() {
	}

	public static void response(int code, HttpServletResponse response) throws IOException {
		response.setContentType("application/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		response.setDateHeader("Expires", 0L);
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		out.print("{\"code\":" + code + "}");
		out.flush();
	}

	public static void response(String msg, HttpServletResponse response) throws IOException {
		response.setContentType("application/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		response.setDateHeader("Expires", 0L);
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		out.print(msg);
		out.flush();
	}

	public static void response(int code,String msg, HttpServletResponse response) throws IOException {
		response.setContentType("application/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		response.setDateHeader("Expires", 0L);
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		out.print("{\"code\": \""+code+"\",\"msg\":\""+msg+"\"}");
		out.flush();
	}
}
